﻿// <copyright file="BlueUserControl.xaml.cs" company="Pelican Design &amp; Development">
//      Copyright (c) Pelican Design &amp; Development. All Rights Reserved.
// </copyright>

namespace BluePlugIn
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.IO;
    using System.Windows;
    using System.Windows.Controls;

    /// <summary>
    /// Simple plugin control with a button which tries to save a file directly.
    /// </summary>
    [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Controls events are explicit enough to be documented.")]
    [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Controls events are explicit enough to be documented.")]
    public sealed partial class BlueUserControl : UserControl
    {
        public BlueUserControl()
        {
            InitializeComponent();

            try
            {
                textBoxContents.Text = AppDomains.DataTools.ReadFileForMe("Blue plugin.txt");
            }
            catch (FileNotFoundException)
            {
                textBoxContents.Text = "<No data>";
            }
        }

        private void buttonSelfSave_Click(object sender, RoutedEventArgs e)
        {
            string dataPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data");
            File.WriteAllText(System.IO.Path.Combine(dataPath, "Blue plugin can hack.txt"), textBoxContents.Text);
        }

        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            AppDomains.DataTools.WriteFileForMe("Blue plugin.txt", textBoxContents.Text);
        }
    }
}
